n = int(input())
if 1000<=n<=9999:
    n1 = str(n//1000%10)
    n2 = str(n//100%10)
    n3 = str(n//10%10)
    n4 = str(n//1%10)
    spis = [int(n1), int(n2), int(n3), int(n4), int(n1+n2), int(n1+n2+n3), int(n1+n2+n3+n4), int(n2+n3), int(n2+n3+n4), int(n3+n4)] 
    spis.sort(reverse = 1)
    for x in spis:
        a = True
        for d in range(2, x//2 + 1):
            if x%d == 0:
                a = False
                break
        if a == True:
                print(x)
                break
    if a == False:
        print (0)
else:
    print(0)


